﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Finance.Web.Models.Accounting
{
    public class YieldDepositAccounting : DepositAmountAccounting
    {
        public double CaclulatePeriodYield(DepostAccounting dep)
        {
            double[] byMonth;
            double result = Calculate(dep, out byMonth);

            return result / dep.Amount.Value - 1;
        }

        public double CaclulateYearYield(DepostAccounting dep)
        {
            double[] byMonth;
            double result = Calculate(dep, out byMonth);

            int period = dep.Deposit.PeriodPayment ?? 12;
            var span = GetSpan(dep.Deposit.PaymentFrequesny);

            return (result / dep.Amount.Value - 1) * (360 / (period * 30));
        }
    }
}